package com.ruoyi.web.controller.datastatistics;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.datastatistics.domain.Realtimegatherdata;
import com.ruoyi.datastatistics.service.IRealtimegatherdataService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 实时数据采集（大）Controller
 *
 * @author ruoyi
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/datastatistics/realtimegatherdata")
public class RealtimegatherdataController extends BaseController {
    @Autowired
    private IRealtimegatherdataService realtimegatherdataService;

    /**
     * 查询实时数据采集（大）列表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdata:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "terminalId", required = false) String terminalId,
                              @RequestParam(value = "terminalName", required = false) String terminalName,
                              @RequestParam(value = "signPlatform",required = false) String signPlatform,
                              @RequestParam(value = "locationNbs",required = false) String[] locationNbs,
                              @RequestParam(value = "loginUserId") Integer loginUserId,
                              @RequestParam(value = "sheetsCode", required = false) String sheetsCode,
                              @RequestParam(value = "systemFlag") Integer systemFlag,
                              @RequestParam(value = "imei", required = false) String imei,
                              @RequestParam(value = "tenantId", required = false) String tenantId) {
        startPage();
        List<Realtimegatherdata> list = realtimegatherdataService.getRealtimegatherdataList(terminalId, terminalName,signPlatform,locationNbs,loginUserId,sheetsCode,systemFlag,imei,tenantId);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdata:list')")
    @GetMapping("/getOne")
    public AjaxResult getOne(@RequestParam(value = "terminalId") String terminalId) {
        return success(realtimegatherdataService.selectRealtimegatherdataByTerminalID(terminalId));
    }

    /**
     * 导出实时数据采集（大）列表
     */
    @PreAuthorize("@ss.hasAnyPermi('datastatistics:realtimegatherdata:export,datastatistics:realtimegatherdata:list')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(value = "terminalId", required = false) String terminalId,
                       @RequestParam(value = "terminalName", required = false) String terminalName,
                       @RequestParam(value = "signPlatform",required = false) String signPlatform,
                       @RequestParam(value = "locationNbs",required = false) String[] locationNbs,
                       @RequestParam(value = "loginUserId") Integer loginUserId,
                       @RequestParam(value = "sheetsCode") String sheetsCode,
                       @RequestParam(value = "systemFlag") Integer systemFlag,
                       @RequestParam(value = "imei",required = false) String imei,
                       @RequestParam(value = "tenantId", required = false) String tenantId) {
        List<Realtimegatherdata> list = realtimegatherdataService.getRealtimegatherdataList(terminalId, terminalName,signPlatform,locationNbs,loginUserId,sheetsCode,systemFlag,imei,tenantId);
        ExcelUtil<Realtimegatherdata> util = new ExcelUtil<Realtimegatherdata>(Realtimegatherdata.class);
        util.exportExcel(response, list, "实时数据采集（大）数据");
    }

    /**
     * 获取实时数据采集（大）详细信息
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdata:query')")
    @GetMapping(value = "/{terminalId}")
    public AjaxResult getInfo(@PathVariable("terminalId") String terminalId) {
        return success(realtimegatherdataService.selectRealtimegatherdataByTerminalID(terminalId));
    }

    /**
     * 新增实时数据采集（大）
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdata:add')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Realtimegatherdata realtimegatherdata) {
        return toAjax(realtimegatherdataService.insertRealtimegatherdata(realtimegatherdata));
    }

    /**
     * 修改实时数据采集（大）
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdata:edit')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Realtimegatherdata realtimegatherdata) {
        return toAjax(realtimegatherdataService.updateRealtimegatherdata(realtimegatherdata));
    }

    /**
     * 删除实时数据采集（大）
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdata:remove')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{TerminalIDs}")
    public AjaxResult remove(@PathVariable String[] TerminalIDs) {
        return toAjax(realtimegatherdataService.deleteRealtimegatherdataByTerminalIDs(TerminalIDs));
    }
}
